package com.glsc.ngateway.common.base.converter.flowable;

import com.glsc.ngateway.common.api.flowable.dto.FlowableCopyDto;
import com.glsc.ngateway.common.base.domain.mysql.flowable.FlowableCopy;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class FlowableCopyConverter {
    @Nullable
    public static FlowableCopy dto2Domain(FlowableCopyDto dto) {
        return Objects.isNull(dto) ? null : FlowableCopy.builder()
                .id(dto.getId())
                .sysid(dto.getSysid())
                .processInstanceId(dto.getProcessInstanceId())
                .processDefinitionKey(dto.getProcessDefinitionKey())
                .usernameSource(dto.getUsernameSource())
                .usernameSourceChinese(dto.getUsernameSourceChinese())
                .usernameDestinationChinese(dto.getUsernameDestinationChinese())
                .usernameDestination(dto.getUsernameDestination())
                .status(dto.getStatus())
                .opTime(dto.getOpTime())
                .title(dto.getTitle())
                .startUser(dto.getStartUser())
                .startUserName(dto.getStartUserName())
                .startTime(dto.getStartTime())
                .readTime(dto.getReadTime())
                .remark(dto.getRemark())
                .build();
    }

    @Nullable
    public static List<FlowableCopy> dto2Domain(List<FlowableCopyDto> dto) {
        return CollectionUtils.isEmpty(dto) ? null: dto.stream().map(FlowableCopyConverter::dto2Domain).collect(Collectors.toList());
    }

    @Nullable
    public static FlowableCopyDto domain2Dto(FlowableCopy domain) {
        return Objects.isNull(domain) ? null : FlowableCopyDto.builder()
                .id(domain.getId())
                .sysid(domain.getSysid())
                .processInstanceId(domain.getProcessInstanceId())
                .processDefinitionKey(domain.getProcessDefinitionKey())
                .usernameSource(domain.getUsernameSource())
                .usernameSourceChinese(domain.getUsernameSourceChinese())
                .usernameDestinationChinese(domain.getUsernameDestinationChinese())
                .usernameDestination(domain.getUsernameDestination())
                .status(domain.getStatus())
                .opTime(domain.getOpTime())
                .title(domain.getTitle())
                .startUser(domain.getStartUser())
                .startUserName(domain.getStartUserName())
                .startTime(domain.getStartTime())
                .readTime(domain.getReadTime())
                .remark(domain.getRemark())
                .build();
    }

    @Nullable
    public static List<FlowableCopyDto> domain2Dto(List<FlowableCopy> domain) {
        return CollectionUtils.isEmpty(domain) ? null: domain.stream().map(FlowableCopyConverter::domain2Dto).collect(Collectors.toList());
    }
}
